package site.edody.dframe.websocket;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;

/**
 *  自带无逻辑监听器
 */
public class SampleWsListener  implements WebSocketListener{

    private static final Logger log = LoggerFactory.getLogger(SampleWsListener.class);

    @Override
    public void onOpen(String sid) {
        log.info("web socket open "+sid);
    }

    @Override
    public void onClose(String sid) {
        log.info("web socket colse "+sid);
    }

    @Override
    public void onMessage(String sid, String message) {
        log.info("web socket  "+sid+"  receive message :"+message);
        try {
            WebSocketCache.getInstance().getWebSocket(sid).sendMessage("you said:"+message);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public void onError(String sid, Throwable error) {
        log.info("web socket  "+sid+" Exception:"+ error);
    }
}
